package thesystem;

import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.Test;

/**
 * @author
 */
public class GoogleStopWatch {

    @Test
    private void t1() throws InterruptedException {
        // 创建一个stopwatch并开始计时
        Stopwatch stopwatch = Stopwatch.createStarted();
        Thread.sleep(1);
        // 从计时到现在过去的时间 res > 100000
        System.out.println(stopwatch.elapsed(TimeUnit.NANOSECONDS));

        // 停止计时
        stopwatch.stop();

        // 再次计时
        stopwatch.start();
        Thread.sleep(100);
        System.out.println(stopwatch.elapsed(TimeUnit.SECONDS));

        // 重置并开始
        stopwatch.reset().start();
        Thread.sleep(1030);

        // 检查是否运行
        System.out.println(stopwatch.isRunning());
        long millis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
        System.out.println(millis);

        // 打印
        System.out.println(stopwatch);

        TimeUnit.SECONDS.sleep(1);
        System.out.println("结束休眠");


    }

    @Test
    private void t2() {
        Stopwatch stopwatch = Stopwatch.createStarted();


    }

}
